<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery/jquery1.9/jquery-1.9.0.js"></script>
    <script>
        $(function(){
            $("input:eq(0)").click(function(){
                $("p:contains(p02):last").css("background","red");
            });
            $("input:eq(1)").click(function(){
                console.log($("p:empty").length);
                $("p:empty").css("background","red").html("我原本是一个空的p标签");
            });
            $("input:eq(2)").click(function(){
                $("div:has(p#hello)").css("background","red");
            });
            $("input:eq(3)").click(function(){
                console.log($("p:not(:empty)").length);
                $("p:not(:empty)").css("background","red");
            });
            $("input:eq(4)").click(function(){

                //p作为父元素(包含文本或者包含子元素)
                console.log($("p:parent").length);
                $("p:parent").css("background","blue");
            });
        });
    </script>
</head>
<body>
    <input type="button" value="选择包含p02的最后一个p元素">
    <input type="button" value="选择空的p元素">
    <input type="button" value="选择包含id为hello的p元素的div元素">
    <input type="button" value="选择非空的p元素(方式一)">
    <input type="button" value="选择非空的p元素(方式二)">
    <div>我是div
        <p id="hello">hello</p>
    </div>
    <div>我是div
        <p >hello2</p>
    </div>
    <div>this is div</div>
    <div>welcome to itany</div>
    <p></p>
    <p>p01</p>
    <p>p02</p>
    <p>p03</p>
    <p>p02</p>
    <p>p04</p>
</body>
</html>